﻿using System;
using System.Linq;
using Google.Protobuf.WellKnownTypes;
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
using Nacos.V2;
using Ocelot.Configuration.Repository;
using Ocelot.DependencyInjection;
using Ocelot.Middleware;
using Ocelot.Provider.Nacos.NacosClient.V2;
using Ocelot.ServiceDiscovery;
using static System.Collections.Specialized.BitVector32;

namespace Ocelot.Provider.Nacos
{
    public static class OcelotBuilderExtensions
    {
        public static IOcelotBuilder AddNacosDiscovery(this IOcelotBuilder builder, string section = "nacos")
        {
            builder.Services.AddNacosAspNet(builder.Configuration, section);
            builder.Services.AddSingleton(NacosProviderFactory.Get);
            builder.Services.AddSingleton(NacosMiddlewareConfigurationProvider.Get);
            builder.Services
               .AddSingleton<IFileConfigurationRepository, NacosFileConfigurationRepository>();

          
            return builder;
        }
    }

    public static class Global
    {
        public static IServiceProvider IServiceProvider;

        public static WebApplication WebApplication;
    }
}
